package cn.bgs.mq.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author:YiChen
 * @program: IntelliJ IDEA
 * @Description:
 * @Created 2021/10/20-14:58
 */
@RestController
@RequestMapping("/mq")
public class controller {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("/message")
    public void message(){
        String message= "发送成功"+"当前时间"+new Date().toString();
        rabbitTemplate.setConfirmCallback((CorrelationData correlationData, boolean ack, String cause)->{

        });
        rabbitTemplate.convertAndSend("email.exchange","email.rotingkey",message,new CorrelationData("1"));
        rabbitTemplate.convertAndSend("shop.exchange","shop.rotingkey",message,msg->{
            msg.getMessageProperties().setDelay(10000);
            return msg;
        }, new CorrelationData("2"));
    }
}
